/**
 * LoginWidow 通用登录窗口
 * 
 * @author zhangzhw
 * @description 通用的登录窗口
 */

Ext.namespace('Ext.ux');

Ext.ux.LoginWindow = Ext.extend(Ext.Window, {
			title : '用户登录',
			bodyStyle : 'padding 10 10 10 10',
			closable : false,
			resizable : false,
			draggable : false,
			width : 300,
			height : 200,
			buttonAlign : 'center',
			layout : 'border',

			initComponent : function() {

				var loginButton = new Ext.Button({
							text : '登录',
							handler : this.login.createDelegate(this)
						});

				var resetButton = new Ext.Button({
							text : '清空',
							handler : this.reset.createDelegate(this)

						});

				this.buttons = [loginButton, resetButton];

				this.loginForm = new Ext.form.FormPanel({
							labelWidth : 100,
							border : false,
							region : "center",
							labelAlign : "right",
							layout : "form",
							labelWidth : 70,
							height : 93,
							modal : true,
							bodyStyle : "padding:10px 10px 10px 10px",
							autoScroll : false,
							items : [{
										xtype : "textfield",
										fieldLabel : "用户名",
										anchor : "90%",
										name : "staffNo",
										id : "staffNo",
										tabIndex : 0,
										allowBlank : false,
										blankText : "用户名不能为空",
										emptyText : "请输入用户名"
									}, {
										xtype : "textfield",
										fieldLabel : "用户密码",
										anchor : "90%",
										name : "password",
										id : "password",
										allowBlank : false,
										blankText : "用户密码不能为空",
										emptyText : "请输入用户密码",
										inputType : "password"
									}]
						});

				this.items = [{
							region : 'north',
							html : '<center><font size=6> CodeHelper</font></center>',
							border : false,
							height : 50
						}, this.loginForm];
				Ext.ux.LoginWindow.superclass.initComponent.call(this);
			},
			login : function() {
				this.loginForm.getForm().submit({
							url : './sys/ajaxlogin!ajaxLogin.action',
							method : 'POST',
							success : this.success,
							failure : this.failure
						});
			},
			reset : function() {
				this.loginForm.getForm().reset();
			},
			success : function(form, action) {
				window.location = "index.jsp";
			},
			failure : function(form, action) {
				if (action.result && action.result.success == false) {

				} else {
					Ext.MessageBox.alert('错误', '连接服务器失败');
				}
			}

		});

Ext.reg('loginwindow', Ext.ux.LoginWindow);